<!--
 * @Author: YWY
 * @Date: 2022-03-05 16:41:29
 * @LastEditors: YWY
 * @LastEditTime: 2022-03-06 21:56:32
-->
<!--
 * @Author: YWY
 * @Date: 2022-02-22 16:17:42
 * @LastEditors: YWY
 * @LastEditTime: 2022-03-05 16:38:24
-->
<template>
  <div id="postCell">
    <p class="van-ellipsis">
      <strong>{{ title }}</strong>
    </p>
    <div class="postcell_main_container">
      <p class="van-ellipsis post_cell_content">{{ content }}</p>
      <div class="post_cell_cover" v-if="cover">
        <img src="@/assets/image/userImg.png" alt="" />
      </div>
    </div>
    <div id="downInfo">
      <ul class="left">
        <li>{{ elapsed }}</li>
        <li style="color: red" v-if="status === 3">待审核</li>
      </ul>
      <ul class="right">
        <li>
          <van-icon name="eye-o" color="#1989fa" class="postcell_visits" />{{
            visits
          }}
        </li>
        <li>
          <van-icon
            name="smile-comment-o"
            color="#1989fa"
            class="postcell_replies"
          />{{ replies }}
        </li>
        <li>
          <van-icon
            name="good-job-o"
            color="#1989fa"
            class="postcell_likes"
          />{{ likes }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { computed } from "@vue/runtime-core";
export default {
  name: "PostCell",
  props: [
    "title",
    "likes",
    "replies",
    "author",
    "postTime",
    "visits",
    "createdAt",
    "updatedAt",
    "content",
    "cover",
    "status",
  ],
  setup(props) {
    const elapsed = computed(() => {
      let space = new Date() - new Date(props.createdAt);

      let minutes = space / 60000;
      let hours = minutes / 60;
      let days = hours / 24;
      let months = days / 30;
      let years = months / 12;

      let obj = {
        年前: years,
        个月前: months,
        天前: days,
        小时前: hours,
        分钟前: minutes,
      };

      for (let key in obj) {
        if (obj[key] >= 1) {
          return Math.floor(obj[key]) + " " + key;
        }
      }
      return "刚刚";
    });

    return {
      elapsed,
    };
  },
};
</script>

<style lang='less'>
#postCell {
  margin: 5px;
  border-bottom: 1px solid rgb(216, 216, 216);
  width: 90vw;
  margin: 10px auto;
  padding-bottom: 10px;
  .van-ellipsis {
    text-align: left;
    margin: 0;
    color: black;
  }
  .postcell_main_container {
    display: flex;
    // border: 1px solid black;
    justify-content: space-between;
    .post_cell_content {
      color: rgb(134, 144, 156);
      font-size: 14px;
      height: 35px;
      // border: 1px solid black;
      text-align: left;
    }
    .post_cell_cover {
      float: right;
      // border: 1px solid black;
      img {
        width: 90px;
        height: 70px;
      }
    }
  }
}

#downInfo {
  display: flex;
  justify-content: space-between;
  .van-icon {
    margin: 3px;
  }
  .left {
    display: flex;
    position: relative;
    justify-content: space-between;
    li {
      margin-right: 5px;
      z-index: 0;
      font-size: 14px;
      line-height: 14px;
      height: 14px;
      // border: 1px solid black;
      text-align: left;
      color: rgb(134, 144, 156);
    }
  }
  .right {
    display: flex;
    position: relative;
    bottom: -1px;
    li {
      z-index: 0;
      font-size: 14px;
      line-height: 14px;
      // border: 1px solid black;
      vertical-align: bottom;
      text-align: left;
    }
    .postcell_replies {
      position: relative;
      bottom: -1px;
    }
  }
}
</style>